﻿using System.ComponentModel;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;

namespace GitSyncApp.Views.Shared
{
    /// <summary>
    /// Header.xaml 的交互逻辑
    /// </summary>
    public partial class Header : UserControl
    {
        private Window parentWindow;

        #region 属性设置
        [Description("窗口标题")]
        public string Title { get; set; } = "";
        [Description("显示最小化按钮")]
        public bool ShowMinimize { get; set; } = false;
        [Description("显示最大化/还原按钮")]
        public bool ShowMaximize { get; set; } = false;
        [Description("圆角设置")]
        public CornerRadius CornerRadius { get; set; } = new CornerRadius(8, 8, 0, 0);
        #endregion

        public Header()
        {
            InitializeComponent();
        }

        private void UserControl_Loaded(object sender, RoutedEventArgs e)
        {
            title.Text = Title;
            min.Visibility = ShowMinimize ? Visibility.Visible : Visibility.Collapsed;
            max.Visibility = ShowMaximize ? Visibility.Visible : Visibility.Collapsed;
            bd.CornerRadius = CornerRadius;
            parentWindow = Window.GetWindow(Parent);
        }

        private void Title_Click(object sender, MouseButtonEventArgs e)
        {
            if(e.ClickCount == 2)
            {
                if(parentWindow.WindowState == WindowState.Normal)
                {
                    parentWindow.WindowState = WindowState.Maximized;
                }
                else
                {
                    parentWindow.WindowState = WindowState.Normal;
                }
            }
        }

        private void Close_Click(object sender, RoutedEventArgs e)
        {
            parentWindow.Close();
        }

        private void Max_Click(object sender, RoutedEventArgs e)
        {
            if (parentWindow.WindowState == WindowState.Normal)
            {
                parentWindow.WindowState = WindowState.Maximized;
            }
            else
            {
                parentWindow.WindowState = WindowState.Normal;
            }
        }

        private void Min_Click(object sender, RoutedEventArgs e)
        {
            if(parentWindow.WindowState != WindowState.Minimized)
            {
                parentWindow.WindowState = WindowState.Minimized;
            }
        }
    }
}
